import { createRouter, createWebHashHistory } from "vue-router";
import { useInfoStore } from "../store/userInfo";
export const routes = [
	{
		path: "/",
        component: () => import("../layout/index.vue"),
        meta: {
            label:"首页"
        },
		redirect: "/index",
		children: [
			{
				path: "/index",
				component: () => import("../views/index.vue"),
				meta: {
					label: "首页",
					icon: "House",
				},
			},
			{
				path: "/product",
				component: () => import("../views/product/index.vue"),
				meta: {
					label: "产品管理",
					icon: "Wallet",
				},
				children: [
					{
						path: "/product/pub",
						component: () => import("../views/product/pub.vue"),
						meta: {
							label: "产品发布",
						},
					},
					{
						path: "/product/list",
						component: () => import("../views/product/list.vue"),
						meta: {
							label: "产品列表",
						},
					},
					{
						path: "/product/detail",
						component: () => import("../views/product/detail.vue"),
						meta: {
							label: "状态页",
						},
					},
				],
			},
			{
				path: "/orders",
				component: () => import("../views/orders/index.vue"),
				meta: {
					label: "订单管理",
					icon: "Document",
				},
				children: [
					{
						path: "/orders/personal",
						component: () => import("../views/orders/personal.vue"),
						meta: {
							label: "个人申请管理",
						},
					},
					{
						path: "/orders/company",
						component: () => import("../views/orders/company.vue"),
						meta: {
							label: "企业申请管理",
						},
					},
					{
						path: "/orders/perDetail",
						component: () => import("../views/orders/personalDetail.vue"),
						meta: {
							label: "状态页",
						},
					},
					{
						path: "/orders/usersList",
						component: () => import("../views/orders/usersList.vue"),
						meta: {
							label: "状态页",
						},
					},
				],
			},
			{
				path: "/user",
				component: () => import("../views/user/index.vue"),
				meta: {
					label: "用户管理",
					icon: "User",
				},
				children: [
					{
						path: "/user/list",
						component: () => import("../views/user/list.vue"),
						meta: {
							label: "用户列表",
						},
					},
					{
						path: "/user/feedback",
						component: () => import("../views/user/feedback.vue"),
						meta: {
							label: "用户反馈",
						},
					},
				],
			},
			{
				path: "/message",
				component: () => import("../views/message/index.vue"),
				meta: {
					label: "消息管理",
					icon: "ChatDotSquare",
				},
				children: [
					{
						path: "/message/list",
						component: () => import("../views/message/list.vue"),
						meta: {
							label: "消息列表",
						},
					},
					{
						path: "/message/pub",
						component: () => import("../views/message/pub.vue"),
						meta: {
							label: "发布消息",
						},
					},
				],
			},
			{
				path: "/role",
				component: () => import("../views/role/index.vue"),
				meta: {
					label: "权限管理",
					icon: "Lock",
				},
				children: [
					{
						path: "/role/role",
						component: () => import("../views/role/role.vue"),
						meta: {
							label: "角色管理",
						},
					},
					{
						path: "/role/reg",
						component: () => import("../views/role/reg.vue"),
						meta: {
							label: "账号管理",
						},
					},
				],
            },
            {
				path: "/table",
				component: () => import("../views/table/index.vue"),
				meta: {
					label: "表格",
					icon: "Tickets",
				},
			},
			{
				path: "/setting",
				component: () => import("../views/setting.vue"),
				meta: {
					label: "状态页",
					icon: "DataAnalysis",
				},
			},
			{
				path: "/updatePwd",
				component: () => import("../views/updatePwd.vue"),
				meta: {
					label: "状态页",
					icon: "DataAnalysis",
				},
			},
		],
	},
	{
		path: "/login",
		component: () => import("../views/login.vue"),
	},
	{
		path: "/reg",
		component: () => import("../views/reg.vue"),
	},
	{
		path: "/visualization",
		component: () => import("../views/visualization/visualization.vue"),
		meta: {
			label: "状态页",
			icon: "DataAnalysis",
		},
	},
];
const router = createRouter({
	history: createWebHashHistory(),
	routes,
});
router.beforeEach((to, from, next) => {
	let userInfo = JSON.parse(localStorage.getItem("userInfo")!);
	if (to.path.indexOf("login") == -1) {
		if (!userInfo) {
			next("/login");
		} else {
			next();
		}
	} else {
		next();
	}
});
export default router;
